package com.boot.selenium.config;

import com.google.j2objc.annotations.Property;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.TimeUnit;

@Configuration
public class WebDriverConfig {

    @Value("${driver.url}")
    private String driverUrl;

    @Value("${driver.name}")
    private String driverName;

    @Value("${driver.exe}")
    private String driverExe;

    @Value("${spring.profiles.active}")
    private String driverActive;

    public WebDriver getWebDriver() {
        //配置驱动
        System.setProperty(driverName, driverExe);
        //new  驱动类    火狐驱动  or   谷歌驱动
        WebDriver browser = "chrome".equals(driverActive) ? new ChromeDriver() : new FirefoxDriver();
        browser.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        browser.get(driverUrl);//测试地址
        return browser;
    }
}
